<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<title>${name_china}管理列表</title>
<%@include file="/common/head.jsp" %>
<style>
/***按钮选中态****/
.pitchbut{
	background:#f86b67;
	color:#fff;
}
</style>
</head>
<body class="iframe-page">
<div class="page-title-wrapper">
    <div class="page-title">
        <div class="page-title-text">
            <span>${name_china}管理</span>
        </div>
        <div id="toolbar" style="float: right"></div>
    </div>
    <div class="page-title-border"></div>
</div>

<div class="search-field">
    <span class="field-cont">
        <span class="field-cont-title">店铺合伙人名称</span>
        <input type="text" class="summer-input" id="partnerName"/>
    </span>
    
     <span class="field-cont">
        <span class="field-cont-title">联系方式</span>
        <input type="text" class="summer-input" id="userPhone"/>
    </span>
    
    <span class="field-cont">
        <span class="field-cont-title">合伙人身份</span>
        <input type="hidden" class="summer-input" id="identity" value="city"/>
    </span>
    
    <span class="field-btn-wrapper">
        <a id="search" class="btn btn-primary btn-icon wave distance-right"><i class="icon icon-search"></i></a>
        <a id="reset" class="btn btn-icon wave wave-dark"><i class="icon icon-refresh"></i></a>
    </span>
</div>

<table class="summer-datagrid" style="width:auto">
		
	    <thead class="orderhead">
	    	<tr>
	    		<th style="width:30%;"><div class="summer-datagrid-cell  pitchbut" style="padding: 9px 8px;"><a id="toCity" href="javascript:;">城市合伙人</a></div></th>
	    		<th style="width:30%;"><div class="summer-datagrid-cell" style="padding: 9px 8px;"><a id="toStore" href="javascript:;">店铺合伙人</a></div></th>
	    		<th style="width:30%;"><div class="summer-datagrid-cell" style="padding: 9px 8px;"><a id="toSale" href="javascript:;">销售合伙人</a></div></th>
	    	</tr>
	    </thead>		
	</table>
	
<div id="t-wrap">
    <table class="summer-datagrid" id="dataList">
	    <thead>
		    <tr>
		        <th>合伙人名称</th>
		        <th>联系方式</th>
		        <th>是否有效</th>
				<th>合伙人类型</th>
				<th>失效日期</th>
		        <th>操作</th>
		    </tr>
	    </thead>
    </table>
</div>

<script>
	//请求url
	var CONST_URL = {
		LIST: basePath + '${common_url}list',
	   	INIT_ADD: basePath + "${common_url}initAdd",
	   	INIT_EDIT: basePath + "${common_url}initEdit",
	   	INIT_VIEW: basePath + "${common_url}initView",
	   	DEL: basePath + "${common_url}del",
	   	EXP: basePath + "${common_url}exp",
		SUCCESS: basePath + "${common_url}success",
	   	INIT_IMP: basePath + "${common_url}initImp",
	   	INIT_CITY_CHECK: basePath + "${common_url}initCityCheck",
	   	INIT_STORE: basePath + "${common_url}initStore",
	   	INIT_SALE: basePath + "${common_url}initSale",
	   	INIT_CITY: basePath + "${common_url}initCity"
	};
	
    var  permission = CommonUtil.getPermission('${name_english}');
    
    $(function () {
    	console.log(permission);
        // 查询按钮
        $('#search').on('click', reloadTable);
        $("#toSale").on('click',toSale);
        $("#toStore").on('click',toStore);
        $("#toCity").on('click',toCity);
        //重置按钮
        $('#reset').on('click', function () {
        	//重置文本框的值
        	$('#partnerName').val('');
        	$('#userPhone').val('');
        	reloadTable();
        });
        
       createTable();
     	
        //查看业绩 initCityCheck
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:initCityCheck"]', function() {
            var $this = $(this),
            id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
            window.location.href = CONST_URL.INIT_CITY_CHECK + '?id=' + id;
        });	
        //initView
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:initView"]', function() {
            var $this = $(this),
            id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
            window.location.href = CONST_URL.INIT_VIEW + '?id=' + id;
        });
        
        
    });
    //跳转到店铺合伙人页面
    function toStore(){
    	console.log("to store");
    	window.location.href = CONST_URL.INIT_STORE;
    }
    //跳转销售合伙人页面
    function toSale(){
    	window.location.href = CONST_URL.INIT_SALE;
    }
    //跳转到城市合伙人
    function toCity(){
    	window.location.href = CONST_URL.INIT_CITY;
    }
    // 重新加载表格
	function reloadTable() {
		$('#dataList').datagrid('reload',{
            ajax: {
            	param: {
            		"partnerName": trimSpace($('#partnerName').val()),
            		"userPhone": trimSpace($('#userPhone').val()),
            		"identity": trimSpace($('#identity').val())
            	}
            }
        });
	}
    
    //创建表格
    function createTable() {
    	$('#dataList').datagrid({
    		ajax: {
    			url: CONST_URL.LIST,
    			param: {
    				"partnerName": trimSpace($('#partnerName').val()),
            		"userPhone": trimSpace($('#userPhone').val()),
            		"identity": trimSpace($('#identity').val())
            	}
    		},
    		columns: [
    		     {
    		    	 field: 'id',
    		    	 hidden: true
    		     },
    		     {
    		    	 field: 'userId',
    		    	 hidden:true
    		     },
    		     {
    		    	 field: 'partnerName',
    		    	 render: function (rowData) {
    		    		 return '<a href="javascript:;" data-permit="${name_english}:initView" class="link">'+ rowData.partnerName +'</a>';
    		    	 }
    		     },
    		     {
    		    	 field: 'userPhone'
    		     },
    		     {
    		    	 field: 'isUsed'
    		     },
    		     {
    		    	 field: 'identity'
    		     },
    		     
    		     {
    		    	 field: 'expiredTime'
    		     },
    		    {
    		    	 render: function (rowData) {
    		    		 return $.funcbar({
    		    			 data: permission,    //请求的数据
    		    			 type: 'text',     //类型
    		    			 display: 1,    //显示数量
    		    			 permit: ['${name_english}:initCityCheck'] //需要的权限按钮
    		    		 });
    		    	 }
    		    }
    		          
    	    ]
    	});
    }

</script>
</body>
</html>